//
//  MultitionObj.m
//  SwiftTest
//
//  Created by mac on 14/10/29.
//  Copyright (c) 2014年 zhouy. All rights reserved.
//

#import "MultitionObj.h"

@implementation MultitionObj

static MultitionObj * staticInstance;
static NSMutableDictionary * staticDic;


+(MultitionObj *)instance{
	@synchronized(self){
        if(staticInstance == nil){
            staticInstance =[[self alloc] init];
        	
            staticDic = [[NSMutableDictionary alloc] init];
            
        }
        
        return staticInstance;
    }
}

+(id) allocWithZone:(struct _NSZone *) zone {
    @synchronized(self){
        if (staticInstance==nil) {
            staticInstance = [super allocWithZone:zone];
        }
        return staticInstance;
    }
    
}

-(Person *)GetPerson:(NSString *)key{
    @synchronized(self){
        Person * obj = [staticDic objectForKey:key];

        if (obj==nil) {
            obj = [[Person alloc] init];
            obj.Key = key;
            obj.Name = [[NSString alloc] initWithFormat: @"  name:%@  ",key ];
            
            
            NSLog(@" NO:%@  Age:%i", obj.Key , obj.Age);
            
            //增加没有对象
            [staticDic setObject:obj forKeyedSubscript:key];
            
            return obj;
        }
        return obj;
    }
}

-(int) GetDicSize{
    NSEnumerator * enumKey =  [staticDic objectEnumerator];
    
    int count =0;
    
    while ([enumKey nextObject]!=nil) {
        count++;
    }

//    for (NSString * key in enumKey) {
//        count++;
//    }

    return count;
}

@end
